﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using PlanningGIS.TocContextMenu.Form;
using PlanningGIS.Framework;

namespace PlanningGIS.TocContextMenu.Button
{
    /// <summary>
    /// 作用：图层属性
    /// </summary>
    public class LayerProperty : BaseCommand
    {
        /// <summary>
        /// 应用程序
        /// </summary>
        IApplication m_Application = null;

        /// <summary>
        /// 构造函数
        /// </summary>
        public LayerProperty()
        {
            base.m_caption = "图层属性";
            base.m_toolTip = base.Caption;
        }

        /// <summary>
        /// 创建按钮
        /// </summary>
        /// <param name="hook"></param>
        public override void OnCreate(object hook)
        {
            if (m_Application == null)
            {
                m_Application = hook as IApplication;
            }            
        }

        /// <summary>
        /// 点击事件
        /// </summary>
        public override void OnClick()
        {
            if (m_Application == null) return;
            ILayer lyr = (m_Application as IFramework).TOCControl.CustomProperty as ILayer;
            if (lyr == null) return;
            FrmLayerProperty frm = new FrmLayerProperty();
            frm.BindLayer = lyr;
            frm.Hook = (m_Application as IFramework).Object;
            if (frm.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
            (m_Application as IFramework).TOCControl.Update();
        }

        /// <summary>
        /// 是否可用
        /// </summary>
        public override bool Enabled
        {
            get
            {
                if (m_Application == null) return false;
                return ((m_Application as IFramework).IsMapCtrlactive && (m_Application as IFramework).TOCControl.CustomProperty is ILayer) ? true : false;
            }
        }

        /// <summary>
        /// 按钮图标
        /// </summary>
        public override int Bitmap
        {
            get
            {
                string bitmapResourceName = "PlanningGIS.TocContextMenu.Res." + this.GetType().Name + ".ico";
                System.IO.Stream stream = GetType().Assembly.GetManifestResourceStream(bitmapResourceName);
                if (stream == null) return 0;

                return new Bitmap(stream).GetHbitmap().ToInt32();
            }
        }
    }
    
}
